package org.linlinjava.litemall.db.domain;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

public class LumiereSubscribeRule {
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    private Integer id;

    private Integer subscribeId;

    private Byte ruleType;

    private Integer daysTimes;

    private Integer weekTimes;

    private String weekDate;

    private Integer monthTimes;

    private Integer monthDate;

    private Integer yearTimes;

    private String yearDate;

    private Integer point;

    private Integer nextSubPoint;

    private BigDecimal price;

    private BigDecimal nextSubPrice;

    private LocalDateTime addTime;

    private LocalDateTime updateTime;

    private Boolean deleted;

    private Integer status;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getSubscribeId() {
        return subscribeId;
    }

    public void setSubscribeId(Integer subscribeId) {
        this.subscribeId = subscribeId;
    }

    public Byte getRuleType() {
        return ruleType;
    }

    public void setRuleType(Byte ruleType) {
        this.ruleType = ruleType;
    }

    public Integer getDaysTimes() {
        return daysTimes;
    }

    public void setDaysTimes(Integer daysTimes) {
        this.daysTimes = daysTimes;
    }

    public Integer getWeekTimes() {
        return weekTimes;
    }

    public void setWeekTimes(Integer weekTimes) {
        this.weekTimes = weekTimes;
    }

    public String getWeekDate() {
        return weekDate;
    }

    public void setWeekDate(String weekDate) {
        this.weekDate = weekDate;
    }

    public Integer getMonthTimes() {
        return monthTimes;
    }

    public void setMonthTimes(Integer monthTimes) {
        this.monthTimes = monthTimes;
    }

    public Integer getMonthDate() {
        return monthDate;
    }

    public void setMonthDate(Integer monthDate) {
        this.monthDate = monthDate;
    }

    public Integer getYearTimes() {
        return yearTimes;
    }

    public void setYearTimes(Integer yearTimes) {
        this.yearTimes = yearTimes;
    }

    public String getYearDate() {
        return yearDate;
    }

    public void setYearDate(String yearDate) {
        this.yearDate = yearDate;
    }

    public Integer getPoint() {
        return point;
    }

    public void setPoint(Integer point) {
        this.point = point;
    }

    public Integer getNextSubPoint() {
        return nextSubPoint;
    }

    public void setNextSubPoint(Integer nextSubPoint) {
        this.nextSubPoint = nextSubPoint;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getNextSubPrice() {
        return nextSubPrice;
    }

    public void setNextSubPrice(BigDecimal nextSubPrice) {
        this.nextSubPrice = nextSubPrice;
    }

    public LocalDateTime getAddTime() {
        return addTime;
    }

    public void setAddTime(LocalDateTime addTime) {
        this.addTime = addTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public void andLogicalDeleted(boolean deleted) {
        setDeleted(deleted ? Deleted.IS_DELETED.value() : Deleted.NOT_DELETED.value());
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", IS_DELETED=").append(IS_DELETED);
        sb.append(", NOT_DELETED=").append(NOT_DELETED);
        sb.append(", id=").append(id);
        sb.append(", subscribeId=").append(subscribeId);
        sb.append(", ruleType=").append(ruleType);
        sb.append(", daysTimes=").append(daysTimes);
        sb.append(", weekTimes=").append(weekTimes);
        sb.append(", weekDate=").append(weekDate);
        sb.append(", monthTimes=").append(monthTimes);
        sb.append(", monthDate=").append(monthDate);
        sb.append(", yearTimes=").append(yearTimes);
        sb.append(", yearDate=").append(yearDate);
        sb.append(", point=").append(point);
        sb.append(", nextSubPoint=").append(nextSubPoint);
        sb.append(", price=").append(price);
        sb.append(", nextSubPrice=").append(nextSubPrice);
        sb.append(", addTime=").append(addTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", deleted=").append(deleted);
        sb.append(", status=").append(status);
        sb.append("]");
        return sb.toString();
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        LumiereSubscribeRule other = (LumiereSubscribeRule) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getSubscribeId() == null ? other.getSubscribeId() == null : this.getSubscribeId().equals(other.getSubscribeId()))
            && (this.getRuleType() == null ? other.getRuleType() == null : this.getRuleType().equals(other.getRuleType()))
            && (this.getDaysTimes() == null ? other.getDaysTimes() == null : this.getDaysTimes().equals(other.getDaysTimes()))
            && (this.getWeekTimes() == null ? other.getWeekTimes() == null : this.getWeekTimes().equals(other.getWeekTimes()))
            && (this.getWeekDate() == null ? other.getWeekDate() == null : this.getWeekDate().equals(other.getWeekDate()))
            && (this.getMonthTimes() == null ? other.getMonthTimes() == null : this.getMonthTimes().equals(other.getMonthTimes()))
            && (this.getMonthDate() == null ? other.getMonthDate() == null : this.getMonthDate().equals(other.getMonthDate()))
            && (this.getYearTimes() == null ? other.getYearTimes() == null : this.getYearTimes().equals(other.getYearTimes()))
            && (this.getYearDate() == null ? other.getYearDate() == null : this.getYearDate().equals(other.getYearDate()))
            && (this.getPoint() == null ? other.getPoint() == null : this.getPoint().equals(other.getPoint()))
            && (this.getNextSubPoint() == null ? other.getNextSubPoint() == null : this.getNextSubPoint().equals(other.getNextSubPoint()))
            && (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice()))
            && (this.getNextSubPrice() == null ? other.getNextSubPrice() == null : this.getNextSubPrice().equals(other.getNextSubPrice()))
            && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
            && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
            && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getSubscribeId() == null) ? 0 : getSubscribeId().hashCode());
        result = prime * result + ((getRuleType() == null) ? 0 : getRuleType().hashCode());
        result = prime * result + ((getDaysTimes() == null) ? 0 : getDaysTimes().hashCode());
        result = prime * result + ((getWeekTimes() == null) ? 0 : getWeekTimes().hashCode());
        result = prime * result + ((getWeekDate() == null) ? 0 : getWeekDate().hashCode());
        result = prime * result + ((getMonthTimes() == null) ? 0 : getMonthTimes().hashCode());
        result = prime * result + ((getMonthDate() == null) ? 0 : getMonthDate().hashCode());
        result = prime * result + ((getYearTimes() == null) ? 0 : getYearTimes().hashCode());
        result = prime * result + ((getYearDate() == null) ? 0 : getYearDate().hashCode());
        result = prime * result + ((getPoint() == null) ? 0 : getPoint().hashCode());
        result = prime * result + ((getNextSubPoint() == null) ? 0 : getNextSubPoint().hashCode());
        result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode());
        result = prime * result + ((getNextSubPrice() == null) ? 0 : getNextSubPrice().hashCode());
        result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
        return result;
    }

    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        subscribeId("subscribe_id", "subscribeId", "INTEGER", false),
        ruleType("rule_type", "ruleType", "TINYINT", false),
        daysTimes("days_times", "daysTimes", "INTEGER", false),
        weekTimes("week_times", "weekTimes", "INTEGER", false),
        weekDate("week_date", "weekDate", "VARCHAR", false),
        monthTimes("month_times", "monthTimes", "INTEGER", false),
        monthDate("month_date", "monthDate", "INTEGER", false),
        yearTimes("year_times", "yearTimes", "INTEGER", false),
        yearDate("year_date", "yearDate", "VARCHAR", false),
        point("point", "point", "INTEGER", false),
        nextSubPoint("next_sub_point", "nextSubPoint", "INTEGER", false),
        price("price", "price", "DECIMAL", false),
        nextSubPrice("next_sub_price", "nextSubPrice", "DECIMAL", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        updateTime("update_time", "updateTime", "TIMESTAMP", false),
        deleted("deleted", "deleted", "BIT", false),
        status("status", "status", "INTEGER", true);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}